<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/v2/console/common/taglibs.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String contextPath = request.getContextPath();
%>

<link rel="stylesheet" href="${path}/v2/console/css/base.css">
<link rel="stylesheet" href="${path}/v2/console/css/style.css">
<script src="${path}/v2/console/js/jquery-1.9.1.min.js"></script>
<script src="${path}/v2/console/js/globle.js"></script>
<script src="${path}/v2/console/My97DatePicker/WdatePicker.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<form id="income" name="incomeform" action="${path}/skillUser/addSkillUserBaseInfo.html" method="post">
  <input type="text" id="name" name="name" placeholder="姓名" />
  <input type="text" id="" name="cityId" value="111" placeholder="城市" />
  <input type="text" name="schoolId" value="1459490853077000" placeholder="学校" />
  <input type="text" name="checkType" placeholder="入驻类型" />
  <input type="text" name="nickname" placeholder="团队名称" />
  <input type="text" name="headPortrait" placeholder="团队头像" />
  <input type="text" id="tel" name="phoneNumber" placeholder="联系电话" />
  <input type="text" id="email" name="email" placeholder="邮箱" />
  <input type="text" id="weixin" name="wxNumber" placeholder="微信号" />
  <input type="text" id="aboutMe" name="aboutMe" placeholder="团队介绍" />
  <input type="text" id="" name="id" value="${basicInfo.id}" />
  
	<input type="button" value="上传" name="图片" onclick="uploadImage();" />
	 <button type="button" class="btn w144" onclick="addSpecial()">保  存</button>
  </form>
<div class="skill-show-body" id="imgId">
																	
</div>
<script type="text/javascript">
var qwx="";
var serverArrayId= new Array();
var arryId= new Array();

function addSpecial(){
	if(serverArrayId.length>0){
		for(var k=0;k<serverArrayId.length;k++){
			downloadImageSelf(wx, serverId[k],arryId[k]); 
			}
	}
	$("#income").submit();
}

/*选择图片*/
function uploadImage() {
	//var imgNum = $("#imgId img").length;
	//var temNum = 9-imgNum;
    var clientUrl = window.location.href;
    var reqPath='<%=contextPath%>/skillUser/getJSConfig.html';
	//请求后台，获取jssdk支付所需的参数
	$.ajax({
		type : 'post',
		url : reqPath,
		dataType : 'json',
		data : {
			"clientUrl" : clientUrl
		//当前页面所在的浏览器URL全路径,由于该支付为jssdk支付，所以需要url地址.参与后台sign签名
		},
		cache : false,
		error : function() {
			alert("系统错误，请稍后重试");
			return false;
		},
		success : function(data) {
			//微信支付功能只有微信客户端版本大于等于5.0的才能调用
			var return_date = eval(data);
			/* alert(return_date ); */
			if (parseInt(data[0].agent) < 5) {
				alert("您的微信版本低于5.0无法使用微信支付");
				return;
			}
			//JSSDK支付所需的配置参数，首先会检查signature是否合法。
			wx.config({
				debug : false, //开启debug模式，测试的时候会有alert提示
				appId : return_date[0].appId, //公众平台中-开发者中心-appid
				timestamp : return_date[0].config_timestamp, //时间戳
				nonceStr : return_date[0].config_nonceStr, //随机字符串,不长于32位
				signature : return_date[0].config_sign, //这里的signature是后台使用SHA1签名算法得出，不是MD5，与下面的wx.chooseWXPay中的paySign不同，下面的paySign是后台使用MD5加密得出
				jsApiList : [ 'chooseImage','uploadImage','downloadImage' ]
			});
			//上方的config检测通过后，会执行ready方法
			wx.ready(function() {
				//uploadImage(wx, "weixin://resourceid/a5d7a699977ccb17c5825011ba0dccf8");
				
				/* alert("ready"); */
				
				wx.chooseImage({
				    count: 9, // 默认9
				    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
				    sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
				    success: function (res) {
						/* for(var j=0;j<9;j++){
							$("#"+j).hide();	     	
						} */
				        var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
				       	imgPath = "";
				        var a=0;
				        /* for(var i=0;i<localIds.length;i++){
					        uploadImageSelf(wx,localIds[i],i);
				        } */
				        uploadImageSelf(wx,localIds,a);
				        $('.skill-show-body:first').show();
				    }
				});

			});
			wx.error(function(res) {
				alert(res.errMsg);
			});
		}
	});
}


function uploadImageSelf(wx,localIds,a){
	 alert("localIds="+localIds); 
	 var i=a;
	 var len = localIds.length;
	 var localId = localIds[i];
	 

		wx.uploadImage({
	        localId: localId, // 需要上传的图片的本地ID，由chooseImage接口获得
	        isShowProgressTips: 1, // 默认为1，显示进度提示
	        success: function (res) {
	            var serverId = res.serverId; // 返回图片的服务器端ID
	            i++;
	            qwx=wx;
	            serverArrayId.push(serverId);
	            arryId.push(i);
	            //downloadImageSelf(wx, serverId,i);
	            /* for(var i=0;i<localIds.length;i++){
	                downloadImageSelf(wx,serverId[i]);
	            } */
	             alert("++len="+len+"i="+i+"localId="+localId); 
	            if(i<len){
	            	uploadImageSelf(wx,localIds,i);
	            }
	        }
	    });
	 
	
}
function downloadImageSelf(wx,serverId,i){
	  alert("downImg="+serverId);  
	$.ajax({
        		type : "post",
        		url : "<%=contextPath%>/skillUser/downloadImageSelf.html",
        		dataType : "json",
        		data : {serverId:serverId},
        		success : function(data) {//success后添加heidden的input用于保存上传服务器返回地址(删除图片,添加img,添加保存地址,保存时获取值)
        			imgPath = data.path;
        		
        		
        			 /* alert(imgPath); */ 
        			/* var u = "http:\//static.xiaoka360.com/uniformStaticResourceService"+imgPath; */
        			var temPara="0";
        			/* var t="add"+i; */
        			var inputImgVal = '<img id="'+i+'" name="imgPath" src="'+imgPath+'" onclick="delImg('+i+','+temPara+');" imgPath="'+imgPath+'" flag="add"></img>';
        			/* alert(inputImgVal); */
        			$("#imgId").append(inputImgVal);
        			/* var h = $("#imgId").html();
        			alert(h); */ 
        			
        		}
        	});
        	/* imgPath = imgPath.subString(0,imgPath.length-1);
        	$("#path").val(imgPath); */
        	/* alert(imgPath); */
   }
//点击删除图片
function delImg(id,imgId){
	/* var imId = this.get(id); */
	var delImgFlag = $("#"+id).attr("flag");
	if(confirm("确定删除?")){
		$("#"+id).remove();		
	}else{
		/* alert("NO"); */
		return ;
	}
	
}
</script>
